  protected function getRedirect(sfWebRequest $request, $<?php echo $this->getSingularName() ?>)
  {
    if ($request->hasParameter('_save_and_add'))
    {
      $redirect = '@<?php echo $this->getUrlForAction('new') ?>';
    }
    elseif ($request->hasParameter('_save_and_list'))
    {
      $redirect = '@<?php echo $this->getUrlForAction('list') ?>';
    }
    else
    {
      $redirect = '@<?php echo $this->getUrlForAction('edit') ?>?<?php echo $this->getPrimaryKeyUrlParams() ?>;
    }

    // If this method returns FALSE, no redirect will be performed after processForm() is executed.
    return $redirect;
  }

  protected function getNotice(sfWebRequest $request, $<?php echo $this->getSingularName() ?>, $notice = '')
  {
    if ($request->hasParameter('_save_and_add'))
    {
      $notice .= ' You can add another one below.';
    }

    return $notice;
  }

  protected function processForm(sfWebRequest $request, sfForm $form)
  {
    $form->bind($request->getParameter($form->getName()), $request->getFiles($form->getName()));
    if ($form->isValid())
    {
      $notice = $form->getObject()->isNew() ? 'The item was created successfully.' : 'The item was updated successfully.';

      $<?php echo $this->getSingularName() ?> = $form->save();

      $this->dispatcher->notify(new sfEvent($this, 'admin.save_object', array('object' => $<?php echo $this->getSingularName() ?>)));
      $event = $this->dispatcher->notify(new sfEvent($this, 'admin.<?php echo $this->getSingularName() ?>_set_flashes_when_saved', array('object' => $<?php echo $this->getSingularName() ?>)));

      $redirect = $this->getRedirect($request, $<?php echo $this->getSingularName() ?>);
      $notice   = $this->getNotice($request, $<?php echo $this->getSingularName() ?>, $notice);

      if (!$event->getReturnValue())
      {
        $this->getUser()->setFlash('notice', $notice);
      }

      if (false !== $redirect)
      {
        $this->redirect($redirect);
      }
    }
    else
    {
      $event = $this->dispatcher->notify(new sfEvent($this, 'admin.<?php echo $this->getSingularName() ?>_set_flashes_when_error', array('object' => $form->getObject())));
      if (!$event->getReturnValue())
        $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false);
    }
  }
